package com.lanzhou.yuanfen.schedule;

import com.lanzhou.yuanfen.sys.service.IVisitorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;


/**
 * 1.主要用于标记配置类，兼备Component的效果。
 * 2.开启定时任务
 *
 * @author Administrator
 */
@Slf4j
@Component
@Configuration
@EnableScheduling
public class ScheduleService {

    @Resource
    private IVisitorService visitorService;

    /**
     * 每天晚上十二点
     */
    private final String cron = "0 0 0 * * ?";

    /**
     * 定时更新聚水潭数据源数据
     */
    @Scheduled(cron = cron)
    private void schedule() {
        log.info("执行动态定时任务: " + LocalDateTime.now().toLocalTime());
        visitorService.reWriteWeekUV();
        log.info("动态定时任务执行结束, 等待下次任务开启 !");
    }


}
